//
//  UIScrollView+YTAdd.m
//  tesDemo02
//
//  Created by 拓客营 on 2022/3/22.
//

#import "UIScrollView+YTAdd.h"
#import <MJRefresh/MJRefresh.h>

@implementation UIScrollView (YTAdd)

- (void)startRefresh{
    [self.mj_header beginRefreshing];
}

- (void)addHeaderWithTarget:(id)target action:(SEL)action{
    
    MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingTarget:target refreshingAction:action];
    
    header.lastUpdatedTimeLabel.hidden = YES;
    header.stateLabel.font = [UIFont systemFontOfSize:12.f];
    header.stateLabel.textColor = [UIColor colorWithRGB:0x999999];
//    header.stateLabel.hidden = YES;
    header.loadingView.color = kRGB(0xBDC1C6);
    [header setTitle:@"下拉刷新" forState:MJRefreshStateIdle];
    [header setTitle:@"松开加载" forState:MJRefreshStatePulling];
    [header setTitle:@"正在加载" forState:MJRefreshStateRefreshing];
    self.mj_header = header;
}


- (void)addFooterWithTarget:(id)target action:(SEL)action{
    MJRefreshBackNormalFooter *footer = [MJRefreshBackNormalFooter footerWithRefreshingTarget:target refreshingAction:action];
    footer.stateLabel.font = [UIFont systemFontOfSize:12.f];
    footer.stateLabel.textColor = [UIColor colorWithRGB:0x999999];
    footer.arrowView.image = nil;
    footer.loadingView.color = kRGB(0xBDC1C6);
    [footer setTitle:@"加载更多" forState:MJRefreshStateIdle];
    [footer setTitle:@"松开加载" forState:MJRefreshStatePulling];
    [footer setTitle:@"正在加载" forState:MJRefreshStateRefreshing];
    [footer setTitle:[NSString stringWithFormat:@"- %@ -",@"已加载全部数据"] forState:MJRefreshStateNoMoreData];
    self.mj_footer = footer;
}

- (void)removeHeader{
    self.mj_header = nil;
}

- (void)removeFooter{
    self.mj_footer = nil;
}

- (void)endRefreshing{
    if (self.mj_header && [self.mj_header isRefreshing]) {
        [self.mj_header endRefreshing];
    }
    
    if (self.mj_footer && [self.mj_footer isRefreshing]) {
        [self.mj_footer endRefreshing];
    }
}

- (void)updateFooterWithEnd:(BOOL)isEnd {
    if (isEnd) {
        [self.mj_footer endRefreshingWithNoMoreData];
    }else {
        [self.mj_footer resetNoMoreData];
    }
}

- (void)updateHeaderWithEnd:(BOOL)isEnd {
    if (isEnd) {
        [self.mj_header endRefreshingCompletionBlock];
    } else {
        [self.mj_footer resetNoMoreData];
    }
}


@end
